package java_test.exception;

public class FinallyDemo {
    public static void main(String[] args) {
        new FinallyDemo().doTheWork();
    }

    private void doTheWork() {
        Object o = null;
        for (int i = 0; i < 5; i++) {
            try {
                o = makeObj(i);
            } catch (IllegalAccessException e) {
                System.err.println("Error: (" + e.getMessage() + ")." + "123123");
                return;
            } finally {
                System.err.println("都已经执行完毕");
                if (o == null)
                    System.exit(0);
            }
            System.out.println(o);
        }
    }

    private Object makeObj(int type)
            throws IllegalAccessException {
        if (type == 4) {
            throw new IllegalAccessException("不是指定的类型" + type);
        }
        return new Object();
    }
}
